<?php

namespace app\http;


use think\worker\Server;
use Workerman\Lib\Timer;

class Worker extends Server
{
	protected $socket = 'websocket://127.0.0.1:2345';
	
	public function onMessage($connection, $data)
	{
		echo "onMessage\n";
		$connection->send("收到啦！！！！！");
	}
	
	/**
	 * 当连接建立时触发的回调函数worker:
	 * @param $connection
	 */
	public function onConnect($connection)
	{
		echo "onConnect\n";
		$connection->send("连接成功");
	}
	
	/**
	 * 当连接断开时触发的回调函数
	 * @param $connection
	 */
	public function onClose($connection)
	{
		echo "close\n";
	}
	
	/**
	 * 当客户端的连接上发生错误时触发
	 * @param $connection
	 * @param $code
	 * @param $msg
	 */
	public function onError($connection, $code, $msg)
	{
		echo "error $code $msg\n";
	}
	
	/**
	 * 每个进程启动
	 * @param $worker
	 */
	public function onWorkerStart($worker)
	{
		echo "onWorkerStart\n";
	}
}